/*
 * @Author: your name
 * @Date: 2021-07-28 18:23:16
 * @LastEditTime: 2021-08-24 19:33:18
 * @LastEditors: GGB
 * @Description: In User Settings Edit
 * @FilePath: \flutter_data_center\lib\screens\home\home_page.dart
 */
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_data_center/components/custom_map.dart';
import 'package:flutter_data_center/conf/config.dart';
import 'package:flutter_data_center/controller/home_controller.dart';
import 'package:flutter_data_center/screens/config/config_screen.dart';
import 'package:flutter_data_center/utills/navigator_utils.dart';
import 'package:get/get.dart';
import '../../../constants.dart';
import 'compoents/attendance_and_task.dart';
import 'compoents/menu_list.dart';
import 'compoents/school_data.dart';
import 'compoents/today_statistics.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key key}) : super(key: key);

  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  HomeController _homeController = Get.put(HomeController());

  @override
  void initState() {
    super.initState();
    // 发起数据请求
    _homeController.getTPStatistics();
    _homeController.getAttendanceStatistics();
    _homeController.getTaskStatistics();
    _homeController.getModules();
    _homeController.getSchoolMoments();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 16),
          child: SingleChildScrollView(
            physics: BouncingScrollPhysics(),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                SizedBox(height: 20),
                buildSchoolName(),
                TodayStatistics(),
                SizedBox(height: 20),
                AttendanceAndTask(),
                SizedBox(height: 20),
                MenuList(),
                SchoolData(),
                SizedBox(height: 20),
                // MapWidget(),
                CustomMap(),
                SizedBox(height: 20),
              ],
            ),
          ),
        ),
      ),
    );
  }

  buildSchoolName() {
    return GestureDetector(
      onTap: () {
        NavigatorUtils.pushPageByFade(
          context: context,
          targetPage: ConfigScreen(),
          isReplace: false,
        );
      },
      child: Text(
        Config.SCHOOL_NAME,
        style: TextStyle(
          fontSize: defaultFontSize,
          fontWeight: FontWeight.w500,
          color: Colors.black,
        ),
      ),
    );
  }
}
